package com.itkaien.javaeebased.multipleSystem;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.locks.ReentrantLock;

public class work7  extends Thread{

    ArrayList<Integer> list;

    public work7(ArrayList<Integer> list) {
        this.list = list;
    }

    public work7() {
    }

    @Override
    public void run() {

        ArrayList boxList=new ArrayList<Integer>();
        ReentrantLock reentrantLock = new ReentrantLock();

        while(true){
        reentrantLock.lock();
        if (list.size()==0){
            System.out.println("Thread "+Thread.currentThread().getName()+" boxList:"+boxList);
            break;
        } else {
            Collections.shuffle(list);
            int price=list.remove(0);
            boxList.add(price);
        }
        reentrantLock.unlock();
        }
    }
}
